﻿<%@ WebHandler Language="C#" Class="MyAjaxHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Linq;

using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;
using Hangjing.WebCommon;

using Newtonsoft.Json;

/// <summary>
/// 处理一般ajax请求:注意，所有方法是不能有参数的
/// </summary>
public class MyAjaxHandler : HandlerBase, System.Web.SessionState.IRequiresSessionState
{
    /// <summary>
    /// 绑定美团商家
    /// </summary>
    public string bindinMtShop()
    {
        int tid = WebUtility.InputText(_httpReuqest["tid"], true);
        string shopName = WebUtility.InputText(base._httpReuqest["name"]).Trim();
        String platformCode = SectionProxyData.GetSetValue(72);

        string url = "http://139.196.169.25:9000/api/shop/bind.do?shopId=" + tid + "&platformCode=" + platformCode+"&shopName="+shopName;

        HttpHelper objhttp = new HttpHelper();
        objhttp.isToLower = false;
        HttpItem objHttpItem = new HttpItem()
        {
            URL = url,
            Encoding = "utf-8",
            Method = "POST"
        };

        string returnmsg = objhttp.GetHtml(objHttpItem);

        return returnmsg;
    }


    /// <summary>
    /// 解绑美团商家
    /// </summary>
    public string unBindinMtShop()
    {
        int tid = WebUtility.InputText(_httpReuqest["tid"], true);
        String platformCode = SectionProxyData.GetSetValue(72);

        string url = "http://139.196.169.25:9000/api/shop/unbind.do?shopId=" + tid + "&platformCode=" + platformCode;

        HttpHelper objhttp = new HttpHelper();
        objhttp.isToLower = false;
        HttpItem objHttpItem = new HttpItem()
        {
            URL = url,
            Encoding = "utf-8",
            Method = "POST"
        };

        string returnmsg = objhttp.GetHtml(objHttpItem);

        return returnmsg;
    }

    /// <summary>
    /// 查询群组
    /// </summary>
    public string searchGroup()
    {
        string key = WebUtility.InputText(base._httpReuqest["q"]).Trim();

        int cityid = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["cityid"]));

        string sql = " 1= 1 ";
        if (cityid > 0)
        {
            sql += " and Status="+cityid;
        }

        StringBuilder sb = new StringBuilder(" ");
        sql += " and className like'%" + key + "%' ";
        IList<DeliverGroupInfo> list = new DeliverGroup().GetList(20, 1, sql, "id", 1);

           //HJlog.toLog(sql);

        foreach (var item in list)
        {
            sb.Append(item.classname + "|" + item.ID + "|" + 0 + "|" + 0 + "|" + 0 + "\n");
        }

        if (list.Count == 0)
        {
            sb.Append("|" + 0 + "|" + 0 + "|" + 0 + "|" + 0 + "\n");
        }

        return sb.ToString();
    }

    /// <summary>
    /// 发送饿了么订单到系统
    /// </summary>
    /// <returns></returns>
    public string sendEleOrder2system()
    {

        string orderid = WebUtility.InputText(base._httpReuqest["orderid"]).Trim();

        CustorderInfo infoaddress = new shopeleCustorder().GetModel(orderid);

        PointsInfo shop = new Points().GetModel(infoaddress.TogoId);


        ETogoLocalInfo info = new ETogoLocalInfo();
        ETogoLocal bll = new ETogoLocal();

        info = bll.GetInfoById(shop.Unid.ToString());

        infoaddress.tempcode = "";
        infoaddress.ReveVar1 = shop.sentorg;
        infoaddress.OldPrice = infoaddress.OrderSums;
        infoaddress.cityid = shop.cityid;
        infoaddress.TogoId = shop.Unid;
        infoaddress.paytime = Convert.ToDateTime("1970-1-1");
        infoaddress.IsShopSet = 1;
        infoaddress.ReveDate1 = DateTime.Now;
        infoaddress.Commission = WebHelper.getShopCommission(infoaddress.OrderSums, shop);
        infoaddress.settlecycle = shop.PType;
        infoaddress.OrderAddress = shop.Name;
        infoaddress.InUse = shop.PHead;
        infoaddress.deliverheaderid = shop.IsCallCenter;
        infoaddress.OldStatus = Convert.ToInt32(shop.PEnd);
        Custorder orderdal = new Custorder();

        apiResultInfo rs = new apiResultInfo();
        rs.state = 0;


        IList<Hangjing.Model.ETogoShoppingCart> Foods = new List<Hangjing.Model.ETogoShoppingCart>();

        Hangjing.Model.ETogoShoppingCart myshopcart = new Hangjing.Model.ETogoShoppingCart();
        myshopcart.TogoId = infoaddress.TogoId;
        myshopcart.sendfree = 0;
        //满多少元免配送费未处理
        myshopcart.ItemList = null;
        myshopcart.latlng = infoaddress.ReveVar2;

        IList<ETogoShoppingCartInfo> foodlist = new List<ETogoShoppingCartInfo>();

        IList<FoodlistInfo> orderfoods = new shopeleFoodlist().GetAllByOrderID(orderid);

        foreach (var item in orderfoods)
        {

            ETogoShoppingCartInfo cartfood = new ETogoShoppingCartInfo();
            cartfood.PId = item.FoodUnid;
            cartfood.PName = item.FoodName;
            cartfood.PNum = item.FCounts;
            cartfood.PPrice = item.FoodPrice;
            cartfood.Currentprice = cartfood.PPrice;
            cartfood.Foodcurrentprice = cartfood.PPrice;
            cartfood.Remark = "";

            foodlist.Add(cartfood);


        }
        myshopcart.ItemList = foodlist;
        Foods.Add(myshopcart);


        ////这里进行所有的判断
        IList<ROrderinfo> mylist = orderdal.SubmitOrder(Foods, infoaddress);

        if (mylist != null)
        {
            if (infoaddress.paystate == 1)
            {
                orderdal.UpdatePayState(infoaddress);
            }

            rs.state = 1;
            rs.data = JsonConvert.DeserializeObject("{\"id\":\"" + infoaddress.orderid + "\",\"lat\":\"" + info.Lat + "\",\"lng\":\"" + info.Lng + "\"}");

            WebUtility.excutesql("UPDATE dbo.shopeleCustorder SET IsShopSet = 1,ReveDate1 = GETDATE() WHERE orderid = '" + orderid + "'");


        }
        else
        {
            rs.msg = "系统错误，请稍后";
        }



        return JsonConvert.SerializeObject(rs);
    }




    /// <summary>
    /// 配送员轨迹
    /// </summary>
    public string getdeliverpath()
    {
        string tid = WebUtility.InputText(base._httpReuqest["tid"]);
        string tbdate = WebUtility.InputText(base._httpReuqest["tbdate"]);

        IList<localInfo> paths = new GPS_Records().GetDeliverPath(Convert.ToInt32(tid), tbdate);
        return JsonConvert.SerializeObject(paths);
    }


    /// <summary>
    /// 查询商品
    /// </summary>
    public string searchfoodByTid()
    {
        int tid = WebUtility.InputText(_httpReuqest["tid"], true);

        StringBuilder sb = new StringBuilder("");


        string sql = " InUse = 'y'";
        sql += " and FPMaster =" + tid;

        IList<EFoodSortInfo> sorts = new EFoodSort().GetListByTogoNum(tid);

        IList<FoodinfoInfo> foodlist = new Foodinfo().GetList(300, 1, sql, "OrderNum", 1);
        foreach (var item in sorts)
        {
            item.Foodlist = foodlist.Where(a => a.FoodType == item.SortID).ToList();
        }

        return Newtonsoft.Json.JsonConvert.SerializeObject(sorts);
    }

    /// <summary>
    /// 搜索商品
    /// </summary>
    public string autosearchfood()
    {
        string key = WebUtility.InputText(_httpReuqest["q"]).Trim();
        int tid = WebUtility.InputText(_httpReuqest["tid"], true);

        StringBuilder sb = new StringBuilder("");


        string sql = " InUse = 'y'";
        sql += " and FPMaster =" + tid;

        if (key.Length > 0)
        {
            sql += " and ( FoodName like '" + key + "%' or FoodNamePy like '" + key + "%'  )  ";
        }

        IList<FoodinfoInfo> list = new Foodinfo().GetList(20, 1, sql, "OrderNum", 1);

        foreach (var item in list)
        {
            sb.Append(item.FoodName + "|" + item.Unid + "|" + item.FPrice + "\n");
        }
        return sb.ToString();
    }


    /// <summary>
    /// 搜索商家
    /// </summary>
    public string autosearchshop()
    {
        string key = WebUtility.InputText(_httpReuqest["q"]).Trim();
        int cid = WebUtility.InputText(_httpReuqest["cid"], true);

        StringBuilder sb = new StringBuilder("");


        string sql = "1=1 and IsDelete = 0 and Star = 1 and InUse = 'Y' and delflag = 0 ";
        if (cid > 0)
        {
            sql += " and cityid =" + cid;
        }
        if (key.Length > 0)
        {
            sql += " and ( name like '" + key + "%' or NamePy like '" + key + "%'  )  ";
        }

        IList<PointsInfo> list = new Points().getShopsBycityid(sql);

        foreach (var item in list)
        {
            sb.Append(item.Name + "|" + item.Unid + "|" + item.Lat + "|" + item.Lng + "|" + 0 + "|" + 0 + "|" + item.Comm + "\n");
        }
        return sb.ToString();
    }


    /// <summary>
    /// 发人
    /// </summary>
    /// <returns></returns>
    public string spreadOne2deliver()
    {
        int did = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["did"]));
        string delivername = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["name"]));
        string IdList = WebUtility.InputText(base._httpReuqest["oids"]);

        OrderDeliver dalod = new OrderDeliver();
        OrderDeliverInfo odmodel = odmodel = new OrderDeliverInfo();
        odmodel.Orderid = IdList;
        odmodel.DeliverId = did;
        odmodel.DeliverName = delivername;
        odmodel.Dispatcher = UserHelp.GetAdmin().AdminName;
        odmodel.DispatchTime = DateTime.Now;
        odmodel.DeliveryTime = DateTime.Now;
        odmodel.Inve1 = 0;
        odmodel.Inve2 = "";
        odmodel.Section = "0";

        dalod.Save(odmodel);

        Custorder bll = new Custorder();

        bll.AddOrderRecord(odmodel.Orderid, 7, odmodel.Dispatcher, "管理员人员列表发人");

        NoticeHelper notice = new NoticeHelper(Context, did.ToString(), IdList);
        notice.sendOrderToDeliver();

        CustorderInfo order = bll.GetModel(IdList);
        if (order.deliverid > 0 && order.deliverid != odmodel.DeliverId)//换人了
        {
            new Deliver().InitWorkState(order.deliverid);
        }

        return "1";


    }

    /// <summary>
    /// 双击调度给配送员
    /// </summary>
    public string spread2deliver()
    {
        Custorder bll = new Custorder();
        int did = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["did"]));
        string delivername = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["name"]));
        string IdList = WebUtility.InputText(base._httpReuqest["oids"]);


        IList<CustorderInfo> orders = bll.GetList(50, 1, "unid in (" + IdList + ")", "unid", 0);

        OrderDeliver dalod = new OrderDeliver();
        foreach (var item in orders)
        {
            OrderDeliverInfo odmodel = odmodel = new OrderDeliverInfo();
            odmodel.Orderid = item.orderid;
            odmodel.DeliverId = did;
            odmodel.DeliverName = delivername;
            odmodel.Dispatcher = UserHelp.GetAdmin().AdminName;
            odmodel.DispatchTime = DateTime.Now;
            odmodel.DeliveryTime = DateTime.Now;
            odmodel.Inve1 = 0;
            odmodel.Inve2 = "";
            odmodel.Section = "0";

            dalod.Save(odmodel);

            bll.AddOrderRecord(odmodel.Orderid, 7, odmodel.Dispatcher, "管理员人员列表发人");

            NoticeHelper notice = new NoticeHelper(Context, did.ToString(), item.orderid);
            notice.sendOrderToDeliver();


        }



        return "1";
    }



    /// <summary>
    /// 判断管理员登录帐号已经可用，可用则返回1，否则返回0（表示已经存在相同的帐号了）
    /// 注意判断是添加，还是编辑
    /// </summary>
    /// <returns></returns>
    public string validAdminAccount()
    {
        string rs = "1";
        string account = WebUtility.InputText(base._httpReuqest["account"]);
        string shopid = base._httpReuqest["shopid"];
        string sql = "AdminName='" + account + "' ";

        if (shopid == null || shopid == "" || shopid == "0")
        {
            //表示是添加
        }
        else
        {
            sql += " and id <> " + shopid;
        }

        EAdmin dal = new EAdmin();
        if (dal.GetCount(sql) > 0)
        {
            rs = "0";
        }
        return rs;
    }

    /// <summary>
    /// 判断配送员帐号已经可用，可用则返回1，否则返回0（表示已经存在相同的帐号了）
    /// 注意判断是添加，还是编辑
    /// </summary>
    /// <returns></returns>
    public string validDeliverAccount()
    {
        string rs = "1";
        string account = WebUtility.InputText(base._httpReuqest["account"]);
        string shopid = base._httpReuqest["shopid"];
        string sql = "UserName='" + account + "' ";

        if (shopid == null || shopid == "" || shopid == "0")
        {
            //表示是添加
        }
        else
        {
            sql += " and dataid <> " + shopid;
        }

        if (new Deliver().GetCount(sql) > 0)
        {
            rs = "0";
        }
        return rs;
    }

    /// <summary>
    /// 判断商家登录帐号已经可用，可用则返回1，否则返回0（表示已经存在相同的帐号了）
    /// 注意判断是添加，还是编辑
    /// </summary>
    /// <returns></returns>
    public string validShopAccount()
    {
        string rs = "1";
        string account = WebUtility.InputText(base._httpReuqest["account"]);
        string shopid = base._httpReuqest["shopid"];
        string sql = "LoginName='" + account + "' ";

        if (shopid == null || shopid == "" || shopid == "0")
        {
            //表示是添加
        }
        else
        {
            sql += " and unid <> " + shopid;
        }

        Points dal = new Points();
        if (dal.GetCount(sql) > 0)
        {
            rs = "0";
        }
        return rs;
    }


    /// <summary>
    /// 未审核配送员提示
    /// </summary>
    public string getnotice()
    {
        EAdminInfo user = UserHelp.GetAdmin();

        string deliversql = " revevar3 =  '0' and delflag =0";
        if (user.CityID > 0)
        {
            deliversql += " and Inve1 =" + user.CityID;
        }
        int noauthdeliver = new Deliver().GetCount(deliversql);
        StringBuilder sb = new StringBuilder("{");



        string nodispatchordersql = " OrderStatus <= 2 and delflag =0";
        if (user.CityID > 0)
        {
            nodispatchordersql += " and CityID =" + user.CityID;
        }
        int nodispatchorder = new Custorder().GetCount(nodispatchordersql);

        sb.Append("\"nodispatchorder\":" + nodispatchorder + ",");





        sb.Append("\"noauthdeliver\":" + noauthdeliver + "");

        sb.Append("}");


        return sb.ToString();
    }


    /// <summary>
    /// 上传分类图片
    /// </summary>
    public string uploadpic()
    {
        string id = WebUtility.InputText(base._httpReuqest["id"]);
        string pic = WebUtility.InputText(base._httpReuqest["pic"]);
        string type = WebUtility.InputText(base._httpReuqest["type"]);
        string sql = "update " + type + " set pic = '" + pic + "' where id =" + id;
        int rat = WebUtility.excutesql(sql);
        return rat.ToString();

    }

    /// <summary>
    /// 实时监控界面统计信息
    /// </summary>
    public string businessmonitor()
    {
        int cityid = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["cityid"]));
        return SectionProxyData.GetCityMonitor(cityid);

    }



    /// <summary>
    /// 判断装备编号已经可用，可用则返回1，否则返回0（表示已经存在相同的帐号了）
    /// 注意判断是添加，还是编辑
    /// </summary>
    /// <returns></returns>
    public string validDeviceSn()
    {
        string rs = "1";
        string account = WebUtility.InputText(base._httpReuqest["account"]);
        string shopid = base._httpReuqest["shopid"];
        string sql = "devNO='" + account + "' and  cityid=" + shopid;

        if (shopid == null || shopid == "" || shopid == "0")
        {
            //表示是添加
        }
        else
        {
            sql += " and dId <> " + shopid;
        }

        Devices dal = new Devices();
        if (dal.GetCount(sql) > 0)
        {
            rs = "0";
        }
        return rs;
    }


    /// <summary>
    ///订单派发后可以撤回成未派发状态
    /// </summary>
    /// <returns></returns>
    public string canceldispatch()
    {
        string orderid = WebUtility.InputText(base._httpReuqest["orderid"]);
        string deliverid = WebUtility.InputText(base._httpReuqest["deliverid"]);

        new Custorder().AddOrderRecord(orderid, 2, UserHelp.GetAdmin().AdminName, "管理员撤回成未派发状态");
        string sql = "UPDATE dbo.Custorder SET OrderStatus = 2 ,sendstate = 0,deliverid = 0 WHERE orderid = '" + orderid + "' ;DELETE dbo.OrderDeliver WHERE OrderId = '" + orderid + "';";
        WebUtility.excutesql(sql);
        if (deliverid != "0")
        {

            NoticeHelper notice = new NoticeHelper(Context, deliverid);

            notice.sendWord2Devlier(Convert.ToInt32(deliverid), "请注意，订单" + orderid + "已经撤回", orderid);

            notice.sendOrderByDeliveryid(Convert.ToInt32(deliverid));

            new Deliver().InitWorkState(Convert.ToInt32(deliverid));
        }

        return "1";
    }




    /// <summary>
    /// 科目二级分类
    /// </summary>
    /// <returns></returns>
    public string getsubfeesort()
    {
        int id = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["id"]));
        IList<AccountsInfo> list = new Accounts().GetsubList().Where(a => a.Parentid == id).ToList();

        string jsonstr = WebUtility.ObjectToJson("sort", list);


        return jsonstr;
    }





    /// <summary>
    ///  添加费用科目二级分类
    /// </summary>
    public string adddevicesort()
    {
        Accounts dal = new Accounts();
        string rs = "0";
        string pid = WebUtility.InputText(base._httpReuqest["pid"]);
        int dataid = Convert.ToInt32(WebUtility.InputText(base._httpReuqest["id"]));
        string name = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["name"]));
        string pri = WebUtility.InputText(base._httpReuqest["pri"]);

        AccountsInfo mm = new AccountsInfo();
        mm.ID = dataid;
        if (mm.ID > 0)
        {
            mm = dal.GetModel(mm.ID);
        }
        mm.Parentid = Convert.ToInt32(pid);
        mm.isDel = 0; ;
        mm.classname = name;
        if (pid == "0")
        {
            mm.Depth = 1;
        }
        else
        {
            mm.Depth = 2;
        }
        mm.Priority = Convert.ToInt32(pri);

        mm.linkurl = "";
        mm.hovepic = "";
        mm.pic = "";


        if (mm.ID == 0)
        {
            if (dal.Add(mm) > 0)
            {
                rs = "1";
            }
        }
        else
        {
            if (dal.Update(mm) > 0)
            {
                rs = "1";
            }
        }

        return rs;
    }


    /// <summary>
    /// 地址复核，且关闭窗口
    /// </summary>
    /// <returns></returns>
    public string checkaddressandCloseWin()
    {
        string admin = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["admin"]));
        string id = WebUtility.InputText(base._httpReuqest["id"]);


        string sql = "UPDATE dbo.Custorder SET OrderChecker = 1 ,settleuser = '" + admin + "' WHERE unid = " + id;
        WebUtility.excutesql(sql);


        return "1";
    }




    /// <summary>
    /// 查询商圈
    /// </summary>
    /// <returns></returns>
    public string searchdeliverGroup()
    {
        string key = WebUtility.InputText(base._httpReuqest["q"]);

        int cityid = Convert.ToInt32(_httpReuqest["cityid"]);


        StringBuilder sb = new StringBuilder("");
        IList<DeliverGroupInfo> list = SectionProxyData.GetEdelivergroupList().Where(a => a.Status == cityid).ToList();

        foreach (var item in list)
        {
            if (item.pic.IndexOf(key) >= 0 || item.classname.IndexOf(key) >= 0)
            {
                sb.Append(item.classname + "|" + item.ID + "\n");
            }

        }
        return sb.ToString();
    }

    /// <summary>
    /// 修改订单处理
    /// </summary>
    public string editData()
    {
        string unid = WebUtility.InputText(base._httpReuqest["unid"]);
        string unidword = WebUtility.InputText(base._httpReuqest["unidword"]);
        string word = WebUtility.InputText(base._httpReuqest["word"]);
        string table = WebUtility.InputText(base._httpReuqest["table"]);
        string msg = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["msg"]));

        string sql = "UPDATE " + table + " SET " + word + " = '" + msg + "' WHERE " + unidword + " = " + unid;
        WebUtility.excutesql(sql);

        return "1";
    }


    /// <summary>
    /// 修改订单处理
    /// </summary>
    public string editOrder()
    {
        string unid = WebUtility.InputText(base._httpReuqest["unid"]);
        string word = WebUtility.InputText(base._httpReuqest["word"]);
        string msg = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["msg"]));

        string oldmsg = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["oldmsg"]));



        string sql = "UPDATE Custorder SET " + word + " = '" + msg + "' WHERE Unid = " + unid;


        if (WebUtility.excutesql(sql) > 0)
        {
            deliverlogInfo item = new deliverlogInfo();
            item.admin = UserHelp.GetAdmin().AdminName;
            item.optime = DateTime.Now;
            item.eventname = "修改";
            item.columntext = "word";
            item.columnname = "";
            item.oldvalue = oldmsg;
            item.newvalue = msg;
            item.reveint1 = 0;
            item.reveint2 = 0;
            item.revevar1 = unid;
            item.revevar2 = "Custorder";

            new deliverlog().Add(item);
        }








        new OrderManager().TellDeliverUpdateInfo(Convert.ToInt32(unid));

        return "1";
    }


    /// <summary>
    /// 计算配送费
    /// </summary>
    public string getSendFee()
    {
        string shopid = WebUtility.InputText(base._httpReuqest["shopid"]);
        string lat = WebUtility.InputText(base._httpReuqest["lat"]);
        string lng = WebUtility.InputText(base._httpReuqest["lng"]);
        string price = WebUtility.InputText(base._httpReuqest["price"]);
        if (price.Length == 0)
        {
            price = "0";
        }

        SendfeeInfo info = new SendfeeInfo();
        info.ShopID = Convert.ToInt32(shopid);
        info.userpay = Convert.ToDecimal(price);
        info.latlng = new latlnginfo();
        info.latlng.ulat = lat;
        info.latlng.ulng = lng;
        


        SendFee fee = new SendFee(info);
        SendInfo model = fee.getSendFee();


        return JsonConvert.SerializeObject(model);
    }


    /// <summary>
    /// 计算配配送员收入
    /// </summary>
    public string getDelivergetfee()
    {
        string shopid = WebUtility.InputText(base._httpReuqest["shopid"]);
        string distance = WebUtility.InputText(base._httpReuqest["distance"]);
        string sendtime = WebUtility.InputText(base._httpReuqest["sendtime"]);

        CustorderInfo order = new CustorderInfo();
        order.cardpay = Convert.ToDecimal(distance);
        order.SendTime = Convert.ToDateTime(sendtime);

        decimal delivergetfee = 0;
        decimal delivergetfee_base = new Custorder().curDeliverGetSendFee(new Points().GetModel(Convert.ToInt32(shopid)), order, out delivergetfee);

        SendInfo model = new SendInfo();
        model.sendmoney = delivergetfee;
        model.Distance = delivergetfee_base;


        return JsonConvert.SerializeObject(model);
    }


    /// <summary>
    /// 操作提出记录
    /// </summary>
    public string setCashOut()
    {
        string cid = WebUtility.InputText(base._httpReuqest["id"]);
        string state = WebUtility.InputText(base._httpReuqest["state"]);
        string msg = Context.Server.UrlDecode(WebUtility.InputText(base._httpReuqest["msg"]));
        string admin = UserHelp.GetAdmin().AdminName;

        string sql = "UPDATE dbo.shopcashout SET opuser = '" + admin + "',optime = GETDATE(),remark = '" + msg + "',state = " + state + " WHERE cid = " + cid;
        int rs = WebUtility.excutesql(sql);
        return rs.ToString();
    }


    /// <summary>
    /// 查询物料
    /// </summary>
    public string searchdDvice()
    {
        string key = WebUtility.InputText(base._httpReuqest["q"].Trim());
        string tid = WebUtility.InputText(base._httpReuqest["tid"]);

        StringBuilder sb = new StringBuilder(" ");
        string sql = " 1=1 and ( title like'%" + key + "%' or  devNO like'%" + key + "%') and delflag = 0 and cityid =  " + tid;
        IList<DevicesInfo> list = new Devices().GetList(20, 1, sql, "did", 1);

        foreach (var item in list)
        {
            sb.Append(item.title + "|" + item.devNO + "|" + item.stock + "|" + item.price + "\n");
        }

        return sb.ToString();
    }


    /// <summary>
    /// 查询商品
    /// </summary>
    public string searchFood()
    {
        string tid = base._httpReuqest["tid"];
        string key = base._httpReuqest["q"];

        StringBuilder sb = new StringBuilder(" ");
        string sql = " 1=1 and ( FoodName like'%" + key + "%' or  FoodNamePy like'%" + key + "%') and FPMaster =" + tid;
        IList<FoodinfoInfo> list = new Foodinfo().GetList(20, 1, sql, "Unid", 1);

        foreach (var item in list)
        {
            sb.Append(item.FoodName + "|" + item.Unid + "|" + item.FPrice + "\n");
        }

        return sb.ToString();
    }


    /// <summary>
    /// 查询商品
    /// </summary>
    public string delPrintOrderLog()
    {
        string pid = WebUtility.InputText(base._httpReuqest["id"]);

        string sql = " UPDATE printorderlog SET printstate = 222 WHERE pid =" + pid;

        WebUtility.excutesql(sql);

        return "1";
    }

    /// <summary>
    /// 根据城市筛选区域
    /// </summary>
    public string changgecity()
    {
        string cid = WebUtility.InputText(base._httpReuqest["id"]);

        ESection dal = new ESection();
        IList<SectionInfo> list = dal.GetList(100, 1, "cityid =" + cid, "SectionID", 1);

        StringBuilder listjson = new StringBuilder();
        listjson.Append("{\"datalist\":[");

        SectionInfo info = new SectionInfo();

        for (int i = 0; i < list.Count; i++)
        {
            info = new SectionInfo();

            info = list[i];

            listjson.Append("{\"id\":\"" + info.SectionID.ToString() + "\",\"name\":\"" + info.SectionName + "\"},");
        }

        listjson.Append("]}");

        HJlog.toLog("listjson=" + listjson);
        return listjson.ToString().Replace("},]}", "}]}");
    }

}
